{extend name="layout"}
{block name="body"}
<div class="index-content" id="listwrap" style="height:100%; overflow:auto;">

    <div class="search-box">
        <input type="hidden" name="status" id="status" value="{$Think.get.status}" />
        <span class="iconfont icon-fangdajing"></span>
        <input type="search" name="search" value="{$Think.get.search}" class="search-head"  placeholder="搜索减员信息" >
    </div>
    <div class="index-tab">
        <a data-status="0" href="{:url('mobile/downsizing/index')}" {if empty($Think.get.status) ||  $Think.get.status eq 0} class="on" {/if}>全部</a>
        <a data-status="1" href="{:url('mobile/downsizing/index')}?status=1" {if $Think.get.status eq 1} class="on" {/if}>待审核</a>
        <a data-status="2" href="{:url('mobile/downsizing/index')}?status=2" {if $Think.get.status eq 2} class="on" {/if}>已审核</a>
        <a data-status="3" {if $total eq true}id="a-red"{/if} href="{:url('mobile/downsizing/index')}?status=3" {if $Think.get.status eq 3} class="on" {/if}>未通过</a>
    </div>
    <div class="index-table" style="padding-bottom: 1.333rem">
        {notempty name='list'}
        {foreach $list as $key=>$vo}
        <div class="table-item">
            <div class="item-title">
                <span>{$vo.code|default=''}</span>
                {if $vo.status eq 1}<span class="color-blue">待审核</span>
                {elseif $vo.status eq 2}<span class="color-desc">已审核</span>
                {elseif $vo.status eq 3}<span class="color-red">未通过</span>
                {/if}
            </div>
            <div class="item-box">
                <p>员工姓名：{$vo.name|default=''}</p>
                <p>身份证号：{$vo.id_number|default=''}</p>
                <p>委托日期：{$vo.create_at|default=''}</p>

            </div>
            <div class="item-button">
                {if $vo.status eq 1}
                <a class="a-edit" href='{:url("mobile/downsizing/edit")}?id={$vo.id}'>编辑</a>
                {elseif $vo.status eq 2}
                <a class="a-view" href='{:url("mobile/downsizing/view")}?id={$vo.id}'>查看</a>
                {elseif $vo.status eq 3}
                <a class="a-feedback" href='{:url("mobile/downsizing/feedback")}?id={$vo.id}'>编辑</a>
                {/if}
            </div>
        </div>

        {/foreach}

        <div class="weui-loadmore" style="display: none">
            <span class="weui-loading iconfont icon-jiazai1"></span>
            <span class="weui-loadmore__tips">正在加载</span>
        </div>
        {/notempty}
        {empty name='list'}
        <div class="table-blank">
            <img src="__ROOT__/static/mobile/images/blank1.png">
            <p>暂无数据</p>
        </div>
        {/empty}
    </div>


</div>
<!--<div class="button-box">-->
<!--    <a href='{:url("mobile/increase/add")}'>立即增员</a>-->
<!--</div>-->
<div class="home-tab">
	<a href="{:url('mobile/index/index')}">
		<span class="iconfont icon-shouye1 "></span>
		<span>首页</span>
	</a>
	<a href="{:url('mobile/index/Business')}">
		<span class="iconfont icon-yewu4 on"></span>
		<span>业务</span>
	</a>
	<a href="{:url('mobile/insbill/index')}">
		<span class="iconfont icon-fuwufeizhangdan"></span>
		<span>账单</span>
	</a>
</div>
{/block}
{block name="script"}
<script>

</script>
<script>
	require(['weui'], function () {

		var pages = 1;
		loading = false;  //状态标记
		if($(".index-table").find('.table-item').length<10){
			loading = true
		}
		$("#listwrap").infinite().on("infinite", function () {
			if (loading) return;
			loading = true;
			pages+=1; //页数
			$('.weui-loadmore').show();
			setTimeout(function () {
				loadlist(pages);
			}, 1000);

		});
	})
	function loadlist(pages) {
		var html = "";
		console.log(pages)
		$.ajax({
			type: "POST",
			url: '{:url("page_list")}',
			data: { 'page': pages,"search" :$(".search-head").val(),status:$(".index-tab .on").attr("data-status")},
			dataType: "json",
			error: function (request) {
				$(".weui-loadmore").hide();
				html += '<div class="weui-cells__title" >已无更多数据</div>';
				$("#listwrap").find('.index-table .table-item:last').after(html);
				loading=true
			},
			success: function (data) {
				if (data.data.length > 0) {

					for (var i = 0; i < data.data.length; i++) {
						var vo = data.data[i]
						var h_span = ""
						var h_a = ""
						if (vo.status ==1){
							h_span =' <span class="color-blue">待审核</span>'
							h_a = ` <a class="a-edit" href='{:url("mobile/downsizing/edit")}?id=${vo.id}'>编辑</a>`
						}else if(vo.status==2){
							h_span = '<span class="color-desc">已审核</span>'
							h_a = `<a class="a-view" href='{:url("mobile/downsizing/view")}?id=${vo.id}'>查看</a>`
						}else if(vo.status == 3){
							h_span = '<span class="color-red">未通过</span>'
							h_a = `<a class="a-feedback" href='{:url("mobile/downsizing/feedback")}?id=${vo.id}'>编辑</a>`

						}

						html += `<div class="table-item">
                                    <div class="item-title">
                                        <span>${vo.code}</span>
                                          ${h_span}
                                    </div>
                                    <div class="item-box">
                                        <p>员工姓名：${vo.name}</p>
                                        <p>身份证号：${vo.id_number}</p>
                                        <p>委托日期：${vo.create_at}</p>

                                    </div>
                                    <div class="item-button">
                                       ${h_a}
                                    </div>
                                </div>`
					}
					$("#listwrap").find('.index-table .table-item:last').after(html);
					loading = false;
					if(data.data.length < 10){
						loading = true;
					}
				}
				else {
					html += "<div class=\"weui-cells__title\" >已无更多数据</div>";
					$("#listwrap").find('.index-table .table-item:last').after(html);
					loading = true;

				}
				$(".weui-loadmore").hide();
			}
		});
	}
	function fmtDate(val){
		if(val>0){
			let date = new Date(val*1000)
			let Y = date.getFullYear();
			let M = date.getMonth() + 1;
			let D = date.getDate();

			if(M < 10) {
				M = '0' + M;
			}
			if(D < 10) {
				D = '0' + D;
			}

			return Y + '-' + M + '-' + D ;

		}else{
			return ""
		}

	}
</script>
{/block}
